<%--
  Created by IntelliJ IDEA.
  User: 11076
  Date: 2018/11/22
  Time: 16:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>

    <%--<base href="<%=basePath%>">--%>
    <title>Title</title>
    <%@ include file="../base/top.jsp" %>


    <style>
        #result_admin{
            width: 90%;
            margin: auto;
            margin-top: 20px;
            padding: 20px;
            box-shadow: 0px 0px 3px #888888 ;
            border-radius: 5px;
            background-color: #FFFFFF;
        }
        .modal-dialog{
            z-index: 9999;
        }
        .dt-bar span{
            background-color: rgb(98,155,88);
            color: white;
            padding: 1px 5px;
            margin: 2px;
            float: left;
            font-size: 14px;
        }
    </style>
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="hr hr-18 dotted hr-double"></div>
                <div class="row">
                    <div class="col-xs-12">
                        <%--datatable--%>
                        <div>
                            <button class="btn btn-primary" id="insert-label" onclick="addLabelLib()">添加</button>
                            <table id="data-table" width="90%" style="margin-left: 5%" class="table table-striped table-bordered">
                                <thead>
                                <tr>
                                    <th>
                                        <input type="checkbox" id="check-all"/>
                                    </th>
                                    <th>序号</th>
                                    <th>标签库名</th>
                                    <th>所含标签</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>

                        </div>
                        <div style="height: 50px;width: 100%">
                        </div>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
    <!-- 返回顶部 -->
    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>


</div>
<%@ include file="../base/foot.jsp" %>
<script>
    var table = null;
    var columnsData = [
        {
            bSortable : false,
            className : "text-center",
            width : "40px",
            render : function(data, type, row, meta) {
                return "<input type=\"checkbox\"/>";
            }
         },
        {
            bSortable : false,
            data: null,
            width : "40px",
            className: 'text-center whiteSpace',
            render:function(data,type,row,meta) {
                return meta.row + 1 +
                    meta.settings._iDisplayStart;
            }
        },
        {'data': 'labelLibName',
            render:function(data,type,row,meta) {
                return "<a onclick=\"showDetail(this)\">"+data+"</a>";
            }
        },
        { 'data': 'labelList',
            width : "50%",
            bSortable : false,
            render: function (data) {
                var html = "";
                html+="<div class=\"dt-bar\">";
                for(var i=0;i<data.length;i++){
                    html += "<span>"+data[i].labelName+"</span>";
                }
                html+="</div>";
                return html;
            }
        },
        {
            bSortable : false,
            className : "text-center",
            width : "100px",
            render : function(data, type, row, meta) {
                var id = '"' + row.id + '"';
                var html = "";
                html += "<a href='javascript:void(0);' onclick='editLabelLib(this)' class='up btn btn-primary btn-xs'><i class='fa fa-arrow-up'></i> 编辑</a> &nbsp;";
                html += "<a href='javascript:void(0);'   onclick='deleteLabelLib(this)'  class='down btn btn-danger btn-xs'><i class='fa fa-arrow-down'></i> 删除</a>";
                return html;
            }
        }
    ];
    var dataBaseFiled =  [
        {'column2': 'label_lib_name'}

    ];
    var url='label_lib/getList';
    var paramter = {test:"name2"};
    $(document).ready(function() {
        table = $('#data-table').DataTable($.extend(true,{},CONSTANT.DATA_TABLES.DEFAULT_OPTION,{

            columns:columnsData,
            ajax: function (data,callback) {
                ajax(data,callback,dataBaseFiled,url,paramter);
            }
        }));
    });


    $("#delect-all").click(function () {
        console.log(getAllCheckedRowValue());
    });


    function showDetail(button) {
        var json =  getClickedRowValue(button);
        var diag = new top.Dialog();
        diag.Drag=true;
        diag.Title ="详情";
        diag.URL = '<%=basePath%>label_lib/view?labelLibId='+json["labelLibId"];
        diag.Width = 550;
        diag.Height = 368;
        diag.CancelEvent = function(){ //关闭事件
            diag.close();
        };
        diag.show();
    }
    function addLabelLib() {
        var diag = new top.Dialog();
        diag.Drag=true;
        diag.Title ="添加";
        diag.URL = "<%=basePath%>label_lib/toAdd";
        diag.Width = 550;
        diag.Height = 368;
        diag.CancelEvent = function(){ //关闭事件
            var success = diag.innerFrame.contentWindow.document.getElementById('success').value;
            var msg = diag.innerFrame.contentWindow.document.getElementById('msg').value;
            diag.close();
            if("true" == success ){
                operateSuccess(msg);
            }else if("false" == success){
                operateError(msg);
            }
        };
        diag.show();

    }
    function editLabelLib(button) {
        var json =  getClickedRowValue(button);
        console.log(json);
        var diag = new top.Dialog();
        diag.Drag=true;
        diag.Title ="编辑";
        diag.URL = '<%=basePath%>label_lib/toEdit?labelLibId='+json["labelLibId"];
        diag.Width = 550;
        diag.Height = 368;
        diag.CancelEvent = function(){ //关闭事件
            var success = diag.innerFrame.contentWindow.document.getElementById('success').value;
            var msg = diag.innerFrame.contentWindow.document.getElementById('msg').value;
            diag.close();
            if("true" == success ){
                operateSuccess(msg);
            }else if("false" == success){
                operateError(msg);
            }
        };
        diag.show();

    }

    function deleteLabelLib(button) {
        var json =getClickedRowValue(button);
        top.bootbox.confirm("确定要删除吗?", function(result) {
            if(result) {
                $.post("<%=basePath%>label_lib/drop",
                    {labelLibId:json['labelLibId'].replace(/\s+/g,"")},
                    function(data){
                        if(data["success"]==true){
                            operateSuccess(data["msg"]);
                        }else if(data["success"]==false){
                            operateError(data["msg"]);
                        }
                    }
                );
            }
        });
    }

</script>

</body>
</html>
